#include "api/text.h"
#include "driver/vga.h"


void Text::load_font( const char& character, const char * filename )
{
    unsigned char * buf_l = 0;
    unsigned char * buf_h = 0;
    
    // open file
    
    for( int i = 0; i < FONT_HEIGHT; i++ )
    {
        for( int j = 0; j < FONT_WIDTH; j++ )
        {
            // read data from the file (2 byte)
            
            // load font data
            m_font[ character ][ i ][ j ] = ( unsigned short ) ( ( *( buf_h ) << 8 ) & 0xFF00 ) | ( *( buf_l ) & 0xFF );
        }
    }
    
    // close file
}

void Text::store_char( const int& grid_id, const char& character )
{
    Vga& vga = Vga::create( );
    vga.store_image( n_loaded_font, ( const unsigned short * ) ( m_font + ( character * FONT_HEIGHT * FONT_WIDTH ) ), FONT_HEIGHT * FONT_WIDTH );
    loaded_font_grid_id[ n_loaded_font ] = grid_id;
    n_loaded_font++;
}

void Text::update_screen( )
{
    Vga& vga = Vga::create( );
    for( int i = 0; i < n_loaded_font; i++ )
    {
        vga.mount_image( loaded_font_grid_id[ i ], i );
    }
}